import request from '@/utils/request'
// 获取员工列表
export const getEmployeeAPI = ({ page, pagesize, departmentId }, keyword) => {
  return request({
    url: '/sys/user',
    method: 'get',
    params: {
      page,
      pagesize,
      keyword,
      departmentId
    }
  })
}

// 新增员工
export const addEmployeeAPI = ({ username, mobile, formOfEmployment, workNumber, departmentId, timeOfEntry, correctionTime, staffPhoto }) => {
  return request({
    url: '/sys/user',
    method: 'post',
    data: {
      username, mobile, formOfEmployment, workNumber, departmentId, timeOfEntry, correctionTime, staffPhoto
    }
  })
}

// 分配角色
export const assignRolesAPI = (id, roleIds) => {
  return request({
    url: '/sys/user/assignRoles',
    method: 'put',
    data: {
      id,
      roleIds
    }
  })
}

// 导出员工
export const exportUsersAPI = () => {
  return request({
    url: '/sys/user/export',
    method: 'get',
    responseType: 'blob'
  })
}

// 导入员工
export const importUsersAPI = (data) => {
  return request({
    url: '/sys/user/import',
    method: 'post',
    data
  })
}

// 下载导入模板
export const downloadTemplateAPI = () => {
  return request({
    url: '/sys/user/import/template',
    method: 'get',
    responseType: 'blob'
  })
}

// 删除员工
export const deleteEmployeeAPI = (id) => {
  return request({
    url: '/sys/user/' + id,
    method: 'delete'
  })
}

// 获取员工基本信息
export const getUserInformation = (id) => {
  return request({
    url: '/sys/user/' + id,
    method: 'get'
  })
}

export const changeEmployeeAPI = (id, { staffPhoto, mobile, username, timeOfEntry, workNumber, correctionTime, departmentId, formOfEmployment }) => {
  return request({
    url: '/sys/user/' + id,
    method: 'put',
    data: {
      staffPhoto,
      id,
      mobile,
      username,
      timeOfEntry,
      workNumber,
      correctionTime,
      departmentId,
      formOfEmployment
    }
  })
}
